{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import bare"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Plot detected interest points over images"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "image_file_name = 'image.tif'\n",
    "ip_file_name = 'image.vwip'\n",
    "\n",
    "ip_csv_file_name = bare.core.write_ip_to_csv(ip_file_name)\n",
    "bare.plot.ip_plot(image_file_name, ip_csv_file_name)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "!['example_plot_IP'](example_plots/interest_points/v2_sub8_interest_points.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Plot match points found between two images"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "image1_file_name = 'image1.tif'\n",
    "image2_file_name = 'image2.tif'\n",
    "match_file_name = 'image1__image2-clean.match'\n",
    "\n",
    "match_csv_file_name = bare.core.write_mp_to_csv(match_file_name)\n",
    "bare.plot.mp_plot(image1_file_name, image2_file_name, match_csv_file_name,out_dir_abs='qc_plots/match_points')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "!['example_plot_mp'](example_plots/match_points/v2_sub8__v3_sub8_match_points.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Plot dxdy after bundle adjustment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "ba_dir = 'bundle_adjust_output_directory/'\n",
    "\n",
    "bare.plot.plot_dxdy(ba_dir)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "!['example_plot_dxdy'](example_plots/dxdy/v3_sub8__v4_sub8_dxdy_plot.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Plot tsai camera xyz positions bef|ore and after bundle adjustment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ba_dir = 'bundle_adjust_output_directory/'\n",
    "img_dir = 'input_image_directory/'\n",
    "input_cam_dir = 'input_cameras_directory/'\n",
    "\n",
    "bare.plot.plot_tsai_camera_positions_before_and_after(ba_dir, input_cam_dir)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "!['example_plot_xy'](example_plots/camera_positions/xy_camera_positions_before_and_after_bundle_adjust.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "!['example_plot_z'](example_plots/camera_positions/z_camera_positions_before_and_after_bundle_adjust.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Plot residuals after bundle adjustment\n",
    "Figure on the right shows outliers is a result of outliers."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ba_dir = 'bundle_adjust_output_directory/'\n",
    "\n",
    "bare.plot.plot_residuals(ba_dir)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "!['example_plot_6'](example_plots/residuals/ba_match_residuals_before_and_after.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Plot WV3 footprint and scanner positions during aquisition."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "image_file_name = 'wv_image.tif'\n",
    "camera_file = 'wv_image.xml'\n",
    "reference_dem = 'reference_dem.tif'\n",
    "\n",
    "bare.plot.plot_footprint(image_file_name,\n",
    "                         camera_file,\n",
    "                         reference_dem)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "!['example_plot_wv_foot_cam'](example_plots/camera_footprint/104001004F176F00.r100_footprint.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Plot WV3 footprint."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "image_file_name = 'wv_image.tif'\n",
    "camera_file = 'wv_image.xml'\n",
    "reference_dem = 'reference_dem.tif'\n",
    "\n",
    "bare.plot.plot_footprint(image_file_name,\n",
    "                         camera_file,\n",
    "                         reference_dem,\n",
    "                         cam_on=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "!['example_plot_wv_foot'](example_plots/camera_footprint/104001004F176F00.r100_footprint_cam_off.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Plot tsai camera footprint and position."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "image_file_name = 'image.tif'\n",
    "camera_file = 'image.tsai'\n",
    "reference_dem = 'reference_dem.tif'\n",
    "\n",
    "bare.plot.plot_footprint(image_file_name,\n",
    "                         camera_file,\n",
    "                         reference_dem)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "!['example_plot_tsai_foot_cam'](example_plots/camera_footprint/v3_sub8_footprint.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Batch plot tsai camera footprints."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "img_dir = 'input_image_directory/'\n",
    "cam_dir = 'input_tsai_camera_directory/'\n",
    "reference_dem = 'reference_dem.tif'\n",
    "\n",
    "bare.batch.plot_footprints(cam_dir, img_dir, reference_dem)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "!['example_plot_multiple_footprints'](example_plots/camera_footprint/footprints.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Run all"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "plotting tsai camera positions before and after bundle adjustment...\n",
      "plotting interest points over images...\n",
      "plotting match points over images...\n",
      "    processing clean.match files only.\n",
      "plotting dxdy...\n",
      "    processing clean.match files only.\n",
      "plotting residuals before and after bundle adjustment...\n"
     ]
    }
   ],
   "source": [
    "ba_dir = 'bundle_adjust_output_directory/'\n",
    "img_dir = 'input_image_directory/'\n",
    "input_cam_dir = 'input_cameras_directory/'\n",
    "\n",
    "bare.batch.plot_all_qc_products(ba_dir,\n",
    "                                img_dir,\n",
    "                                input_cam_dir,\n",
    "                                img_extension='8.tif')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
